home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AlexNeXTSTEPSource / Source / Chapter8_Prefs / PopUp / PopUp_main.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  89 lines

  1. #import <appkit/appkit.h>
  2. #import "TargetObject.h"
  3.  
  4. // a minimal program to demonstrate how
  5. // to use a popuplist
  6.  
  7. main()
  8. {
  9.     // create an application object
  10.     // to establish connection to
  11.     // Window Server
  12.     id NXApp = [Application new];
  13.     id theWindow;
  14.     id theMenu;
  15.     id theButton;
  16.     NXRect theRect;
  17.     id thePopUpList;
  18.     id theTargetObject;
  19.     id menuCell;
  20.  
  21.     // create a window that's at 125, 125
  22.     // and is 200 by 300 pixels
  23.     NXSetRect(&theRect, 125, 125, 200, 300);
  24.     theWindow = [ [Window alloc]
  25.         initContent:&theRect
  26.         style: NX_TITLEDSTYLE
  27.         backing:NX_BUFFERED
  28.         buttonMask:NX_MINIATURIZEBUTTONMASK
  29.         defer:YES];
  30.  
  31.     // create the menu
  32.     theMenu = [ [Menu alloc]
  33.         initTitle: [NXApp appName]];
  34.     // create the menu option
  35.     [theMenu addItem:"Quit"
  36.         action:@selector(terminate:)
  37.         keyEquivalent:'q'];
  38.  
  39.     // resize menu to accomodate menu option
  40.     [theMenu sizeToFit];
  41.     [NXApp setMainMenu:theMenu];
  42.  
  43.     // create a button that's 80 x 20
  44.     NXSetRect(&theRect, 0, 0, 80, 20);
  45.     theButton = [ [Button alloc]
  46.         initFrame:&theRect];
  47.     // set the title for the button
  48.     [theButton setTitle:"Press Here"];
  49.     // since the button is a view, we need
  50.     // to install it as the subview of the
  51.     // window's contentview or else it
  52.     // won't draw
  53.     [ [theWindow contentView]
  54.         addSubview: theButton];
  55.  
  56.     // create the target of the popuplist
  57.     theTargetObject = 
  58.         [[TargetObject alloc] init];
  59.     
  60.     // create the popuplist
  61.     thePopUpList = [[PopUpList alloc] init];
  62.     // add items to the popup list
  63.     // and set each tag
  64.     // addItem: returns the added menucell
  65.     menuCell = [thePopUpList addItem:"Item 1"];
  66.     [menuCell setTag:1];
  67.     menuCell = [thePopUpList addItem:"Item 2"];
  68.     [menuCell setTag:2];
  69.     menuCell = [thePopUpList addItem:"Item 3"];
  70.     [menuCell setTag:3];
  71.  
  72.     // set the target and action for
  73.     // the popup list
  74.     [thePopUpList setTarget:theTargetObject];
  75.     [thePopUpList
  76.         setAction:@selector(printSelection:)];
  77.     
  78.     // attach button to popuplist
  79.     NXAttachPopUpList(theButton,
  80.         thePopUpList);
  81.  
  82.     // send the window to the front
  83.     // and display it
  84.     [theWindow makeKeyAndOrderFront:nil];
  85.  
  86.     // go into event loop to wait for events
  87.     [NXApp run];
  88. }
  89.